package com.lbt.javaSE.jianzhioffer;

public class JZ12 {
    public double Power(double base, int exponent) {
        if(exponent==0) return 1.0;
        if (exponent==1) return base;
        double sum=base;
        double sum2=1/base;
        if(exponent<0){
            if(exponent==-1) return sum2;
            base=sum2;
            int count = Math.abs(exponent);
            for(int i=2;i<=count;i++){
                base*=sum2;
            }
            return base;
        }

        for(int i=2;i<=exponent;i++){
            base=base*sum;
        }
        return base;

    }

    public static void main(String[] args) {
        double power = new JZ12().Power(2, -3);
        System.out.println(power);
    }
}
